package org.footballmanager.pandafootball.system.controller;

import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.form.impl.FootLotterySearchForm;
import org.footballmanager.pandafootball.system.service.FootLotteryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@SessionAttributes("footLotterySearchForm")
@RequestMapping("/foot/footLottery")
public class FootLotteryController extends BaseController{
	/* 实体名称 */
	private static final String ENTITYNAME = "footLottery";
	private static final String LISTPAGE = String.format(Constants.LISTPAGE, Constants.FOOT, ENTITYNAME);
	private static final String VIEWPAGE = String.format(Constants.VIEWPAGE, Constants.FOOT, ENTITYNAME);

	@Autowired
	private FootLotteryService footLotteryService;

	/**
	 * 初始化
	 * @param map 参数
	 * @param footLotterySearchForm 条件参数
	 */
	@ModelAttribute
	public void init(Model map, @ModelAttribute FootLotterySearchForm footLotterySearchForm){
		FootLotterySearchForm newFootLotterySearchForm = new FootLotterySearchForm();
		if(footLotterySearchForm != null){
			newFootLotterySearchForm = footLotterySearchForm;
		}
		map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), newFootLotterySearchForm);
	}

	@RequestMapping(value="/search")
	public String search(Model map, @ModelAttribute FootLotterySearchForm footLotterySearchForm) {
        footLotteryService.search(ENTITYNAME, map, footLotterySearchForm);
		return LISTPAGE;
	}
	
	@RequestMapping(value = "/view", method = RequestMethod.GET)
	public String openViewPage(Model map, @RequestParam Long id, @ModelAttribute FootLotterySearchForm footLotterySearchForm) {
		map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), footLotterySearchForm);
		map.addAttribute(ENTITYNAME, footLotteryService.get(id));
		return VIEWPAGE;
	}	

}
